const list = [1, 2, 5, 18, 25, 33, 45, 99];
// 二分查找
const binarySearch = (list, target) => {
  let left = 0;
  let right = list.length - 1;
  if (!right) return -1;
  if (right == 1) {
    return list[0] === target ? 0 : -1;
  }
  let mid;

  while (left <= right) {
    mid = ((left + right) / 2) | 0; //向下取整
    if (list[mid] === target) {
      return mid;
    }
    if (list[mid] < target) {
      left = mid + 1;
    }
    if (list[mid] > target) {
      right = mid - 1;
    }
  }
  return -1;
};

console.log(binarySearch(list, 1));
